package com.cwnu.service.impl;

import com.cwnu.entity.Article;
import com.cwnu.entity.FeedBack;
import com.cwnu.entity.PageBean;
import com.cwnu.mapper.FeedbackMapper;
import com.cwnu.service.FeedbackService;
import com.cwnu.utils.TokenUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FeedbackServiceImpl implements FeedbackService {
    @Autowired
    private FeedbackMapper feedbackMapper;

    @Override
    public boolean add(FeedBack feedBack) {
        int i = feedbackMapper.add(feedBack);
        return i == 1;
    }

    @Override
    public PageBean<FeedBack> getFeedbackList(Integer pageNum, Integer pageSize) {
        // 1、创建pageBean对象
        PageBean<FeedBack> pb = new PageBean<>();

        // 2、开启分页查询，使用pageHelper插件
        PageHelper.startPage(pageNum, pageSize);

        // 3、调用mapper
        List<FeedBack> as = feedbackMapper.list();
        // page中提供了方法，可以获取总记录条数和当前页数据
        Page<FeedBack> p = (Page<FeedBack>) as;
        // 把数据填充到pageBean对象中
        pb.setTotal(p.getTotal());
        pb.setItems(p.getResult());
        return pb;
    }
}
